package com.chendongyang.www.service;//进行用户对停车的选择（停车或结束停车）
import com.chendongyang.www.dao.stop;
import com.chendongyang.www.po.parkingstation;
import com.chendongyang.www.util.userId;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;
public class stops {
    public  void stoping() throws SQLException {
        stop udi=new stop();
        ArrayList<parkingstation> list = udi.select1();
        ArrayList<parkingstation> List=udi.select(userId.Id);
        System.out.println("===============");
        System.out.println(userId.Id);
        if(List.size()==1){
            System.out.println("您的车现在正在停车位中");
            System.out.println("该停车位是：");
            System.out.println(List.get(0));
            System.out.println("====================");
            System.out.println("请选择是否继续停车");
            System.out.println("1    继续停车");
            System.out.println("2    结束停车");
            Scanner input = new Scanner(System.in);
            int op=input.nextInt();
            if(op==2){
                int number= udi.over(userId.Id);
                if(number==1) System.out.println("结束成功");
                System.out.println("======================");
            }
        }
        else {
            System.out.println("现有以下可用停车位");
            int m = list.size();
            for (int i = 0; i < m; i++) {
                System.out.print(i + 1 + ":");
                System.out.println(list.get(i));
            }
            System.out.println("================");
            System.out.println("请选择停车位进行停车");
            Scanner input = new Scanner(System.in);
            int op = input.nextInt();
            String station = list.get(op - 1).getParkingS();
            String bit = list.get(op - 1).getParkingB();
            int line = udi.update(station, bit,userId.Id);
            if (line == 1) {
                System.out.println("已在该位置停好车");
                System.out.println("===================");
            } else {
                System.out.println("停车失败");
                System.out.println("====================");
            }
        }
    }
}
